#ifndef __CLIENT_H_
#define __CLIENT_H_

#include<stdio.h>
#include<sys/types.h>          /* See NOTES */
#include<sys/socket.h>
#include<arpa/inet.h>
#include<netinet/in.h>
#include<string.h>
#include<pthread.h>
#include<json/json.h>
#include<unistd.h>
#include<sqlite3.h>
#include<stdlib.h>
#include<signal.h>
#include<semaphore.h>
#include<syslog.h>
#define UID_LENTGTH 11
#define PWD_LENGTH  128
#define MSG_LENGTH  256

typedef struct {
    int sockfd;
    struct sockaddr_in server; // 声明结构体,并即将给里面成员赋值
    int sig;
} MISC;

//4 + 4 + 11 + 128 + 
typedef struct {
    int fd;
    unsigned long cmd;
    char uid[UID_LENTGTH];
    char passwd[PWD_LENGTH];
    char msg[MSG_LENGTH];
} INFO;

enum {
    SIGNUP = 0,  //注册
    LOGIN,      //登录
    BK_LOGIN,
    
};

//2024年7月31日21:59:03
void info_To_Json (INFO *info, char *buf);
void connect_To_Server(void);
void json_To_Info(char *buf, INFO *info);

//---------------------------------------

struct user{
    char uid[20];
    char passwd[20];
    int fd;
};
struct bro{
    char uid[50];
    int status;
};
struct msg{
    int status;
    char msg[70];
};

struct info{
    char m_uid[50];
    char b_uid[50];
};
struct msg_node{
    char uid[50];
    char msg[100];
    struct msg_node * next;
};
struct msg_que{
    struct msg_node *head;
    struct msg_node *tail;
};

void info_recv(int fd, void *arg);
void json_user(char *p, void *info);
void clear_up(int row, int column, int num);
void pop_up(char *, int time);

void main_page();
void init_page();
void page_frame();
void sign_page();

void * client_ctrlc(void *arg);

int exit_server(int fd);
void sig_send(int fd, char *sig);

void *recvinfo(void *arg);
void *sendinfo(void *arg);

void end_sig(int arg);
void sig_exit(int sockfd);
void send_exit(int a);

void info_json(void *info, char *buf);
void info_rejson_array(void *info, char *p, int *len);

void talk_to(void *info, char *uid);
int sign_in(void *, char *);
int log_in(void *, char *);
void log_out(int);

void first(void); //最开始的选择登录注册退出的界面
void log_dis(void); //登录操作时的界面
void reg_dis(void);  //注册时的界面
void log_wait(void);  //登录等待返回时界面
void log_succes(void);
int add_bro(void *info);
int del_bro(void *info);
int re_fresh(int sockfd, void *info);

void qq_show(void);
void qq_show1(void);
int exit_server(int fd);

void info_rejson_arry(void *info, char *p); //struct bro结构体数组解包（多个好友的信息--uid和status）
void *passive(void *arg);
/*
   printf输出带颜色字体

   [http://hi.baidu.com/lukunnr/blog/item/cd3b4e5429d098c8b745ae86.html]

   printf输出颜色和ANSI控制码(高亮,下划线,闪烁,光标位置,清屏等)
   给printf的输出加上些特效比如颜色，可以让打印信息更鲜明，在debug的时候特别有用。

   颜色：
 */
#define NONE "\033[m"

#define RED "\033[0;32;31m"

#define LIGHT_RED "\033[1;31m"

#define GREEN "\033[0;32;32m"

#define LIGHT_GREEN "\033[1;32m"

#define BLUE "\033[0;32;34m"

#define LIGHT_BLUE "\033[1;34m"

#define DARY_GRAY "\033[1;30m"

#define CYAN "\033[0;36m"

#define LIGHT_CYAN "\033[1;36m"

#define PURPLE "\033[0;35m"

#define LIGHT_PURPLE "\033[1;35m"

#define BROWN "\033[0;33m"

#define YELLOW "\033[1;33m"

#define LIGHT_GRAY "\033[0;37m"

#define WHITE "\033[1;37m"

/*
   比如：

   printf("\033[31m ####-----&gt;&gt; \033[32m" "hello\n" "\033[m")

   int main()

   {

   printf( CYAN "current function is %s " GREEN " file line is %d\n" NONE,

   __FUNCTION__, __LINE__ );

   fprintf(stderr, RED "current function is %s " BLUE " file line is %d\n" NONE,

   __FUNCTION__, __LINE__ );

   return 0;

   }
 */

/*颜色分为背景色和字体色，30~39用来设置字体色，40~49设置背景：

  背景色 字体色

40: 黑 30: 黑

41: 红 31: 红

42: 绿 32: 绿

43: 黄 33: 黄

44: 蓝 34: 蓝

45: 紫 35: 紫

46: 深绿 36: 深绿

47: 白色 37: 白色

记得在打印完之后，把颜色恢复成NONE，不然再后面的打印都会跟着变色。
 */
//另外，还可以加一些ANSI控制码。加颜色只是以下控制码中的一种：

#define CLOSE "\033[0m"  //关闭所有属性

#define HIGH "\033[1m"  //设置高亮度

#define LINE "\033[4m"  //下划线

#define LIGHT "\033[5m"  //闪烁

#define F1 "\033[7m"  //反显

#define F2 "\033[8m" //消隐

#define fore1 "\033[30m"
#define fore2 "\033[31m"
#define fore3 "\033[32m"
#define fore4 "\033[33m"
#define fore5 "\033[34m"
#define fore6 "\033[35m"
#define fore7 "\033[36m"
#define fore8 "\033[37m"

#define back1 "\033[0;32;40m"
#define back2 "\033[0;32;41m"
#define back3 "\033[42m"
#define back4 "\033[43m"
#define back5 "\033[44m"
#define back6 "\033[45m"
#define back7 "\033[46m"
#define back8 "\033[47m"
//\033[30m -- \033[37m 设置前景色
//\033[40m -- \033[47m 设置背景色

#define LOGSLEEP 150000



#endif
